function createNonSortedArray(size) { //{6}
    var array = new ArrayList();
    for (var i = size; i > 0; i--) {
        array.insert(i);
    }
    return array;
}

function ArrayList() {
    var array = []; //{1}
    this.insert = function (item) { //{2}
        array = [-1, 0, 2, 3, 3, 7, 8, 9,6,10,4];
        // array.push(item);
    };
    this.toString = function () { //{3}
        return array.join();
    };
    this.quickSort = function () {
        this.quick(array,0,array.length - 1);
    };
    this.quick = function (arr,left,right) {

        if(arr.length > 1){
            let minIndex = Math.floor((left + right)/2);
            while (left < right ){
                while (arr[left] < arr[minIndex] && left < minIndex){
                    left++;
                }
                while (arr[right] > arr[minIndex] && right > minIndex){
                    right--;
                }
                if(arr[left] > arr[right]){
                    swap(arr,left,right);
                }
            }
            let leftArr = arr.slice(left,minIndex-1);
            let rightArr = arr.slice(minIndex+1,right);
            this.quick(leftArr,left,minIndex-1);
            this.quick(rightArr,minIndex+1,right);
        }
    }
}

function swap(arr,l,r){
    let temp = arr[l];
    arr[l] = arr[r];
    arr[r] = temp;
}
let array = createNonSortedArray(8); //{7}
console.log(array.toString()); //{8}
array.quickSort();
console.log(array.toString()); //{8}
